package yesjava;

import java.util.Objects;

//具备自然排序能力
public class Person /*implements Comparable<Person>*/{ // 给类定义一个比较的规则
    private String name;
    private Integer age;

   /* public int compareTo(Person o) {
        return this.age - o.getAge();
    }*/

    public Person() {
    }

    public Person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public Integer getAge() {
        return age;
    }

    public Person setAge(Integer age) {
        this.age = age;
        return this;
    }



    public Person(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public Person setName(String name) {
        this.name = name;
        return this;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(name, person.name);
    }

   @Override
    public int hashCode() {
        return Objects.hash(name);
    }
}
